<template>
  <div class="task-view">
    <div class="shade"></div>
    <div class="popup">
      <div class="title justify-content-between">
        <span class="fs28 colorFFF">任务查看</span>
        <img src="../assets/images/icon-close.png" @click="cancel" />
      </div>
      <div class="content" v-loading="loading">
        <div v-if="taskData">
          <div class="align-item-center fs18 color161D2E">{{ taskData.taskName }}</div>
          <div class="justify-content-between">
            <div class="t-title">
              共<span>{{ total }}</span
              >套，分为<span>{{ group }}</span
              >组
            </div>
            <div
              class="btn-xiafa justify-content-center"
              @click="issuedHandle()"
            >
              <img src="../assets/images/icon-down.png" />
              <span class="fs18 color285FE3 ml6">下发</span>
            </div>
          </div>
          <div class="theader justify-content-between">
            <div class="w500">分组</div>
            <div class="w7000">下发任务</div>
            <div class="w1000 justify-content-center">
              <span>操作终端</span>
              <div class="triangle"></div>
            </div>
            <div class="w1000 justify-content-center">
              <span>执行情况</span>
              <div class="triangle"></div>
            </div>
          </div>
          <div class="tbodys">
            <div
              class="tbody justify-content-between"
              v-for="(item, index) in taskList"
              :key="index"
            >
              <div class="w500">{{ index + 1 }}</div>
              <div class="w7000">{{ item.matchNames }}</div>
              <div class="w1000">{{ item.optClientName }}</div>
              <div class="w1000 color5379E6" v-if="item.groupStatus.code == 'DOING'">进行中</div>
              <div class="w1000 color00A65E" v-else-if="item.groupStatus.code == 'COMP'">已完成</div>
              <div class="w1000 colorEE5400" v-else>未开始</div>
            </div>
          </div>
        </div>
      </div>
      <div class="btns justify-content-center">
        <div class="btn sure" @click="cancel">确认</div>
        <div class="btn cancel" @click="cancel">取消</div>
      </div>
    </div>
  </div>
</template>

<script>
import Bus from "@/assets/js/bus.js";
export default {
  name: "TashView",
  props: {
    taskData: Object
  },
  data() {
    return {
      loading: false, //加载中
      taskList: null, //弹窗数据
      total: '',
      group: ''
    };
  },
  created() {
    let _this = this;
    _this.getGroupList();
    Bus.$on("refreshTaskView", () => {
      _this.getGroupList();
    });
  },
  methods: {
    // 关闭弹窗
    cancel() {
      this.$emit("cancel");
    },
    // 下发
    issuedHandle() {
      Bus.$emit("issued", this.taskData);
    },
    // 查询下发分组情况
    getGroupList() {
      let _this = this;
      let params = {
        taskId: _this.taskData.id,
      };
      _this.loading = true;
      _this.axios
        .getTaskGroup(params)
        .then((res) => {
          console.log(res);
          if (res.code == 200) {
            res.data.map(item => {
              let len = item.matchIds.split(',').length;
              _this.total = Number(_this.total) + Number(len)
            })
            _this.taskList = res.data;
            _this.group = res.data.length
          }
          _this.loading = false;
        })
        .catch(function (error) {
          _this.loading = false;
          if (error.msg) _this.$message.error(error.msg);
        });
    },
  },
};
</script>

<style scoped lang='less'>
.task-view {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
  .shade {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
  }
  .popup {
    width: 12.43rem;
    height: 5.84rem;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #fff;
    box-shadow: 0 .05rem .15rem 0 rgba(0, 21, 54, 0.25);
    .title {
      width: 100%;
      height: .58rem;
      background-color: #285fe3;
      padding: 0 .25rem 0 .4rem;
      img {
        width: .23rem;
        height: .23rem;
        cursor: pointer;
      }
    }
    .content {
      width: 100%;
      padding: .14rem .4rem 0;
      .t-title {
        margin-top: .18rem;
        font-size: .18rem;
        color: #505971;
        span {
          color: #285fe3;
        }
      }
      .btn-xiafa {
        width: 1rem;
        height: .34rem;
        border: 1px solid #316eff;
        background: linear-gradient(0deg, #d8dce7 0%, #ffffff 100%);
        border-radius: .03rem;
        cursor: pointer;
      }
      .theader {
        width: 100%;
        height: .36rem;
        background: #f4f5f8;
        border: 1px solid #d0d6e3;
        border-radius: .03rem;
        padding: 0 .3rem 0 .15rem;
        margin-top: .07rem;
        .triangle {
          width: 0;
          height: 0;
          border-top: .08rem solid #505971;
          border-left: .08rem solid transparent;
          border-right: .08rem solid transparent;
          margin-left: .05rem;
        }
      }
      .theader > div {
        text-align: center;
        font-size: .18rem;
        color: #505971;
      }
      .tbodys {
        width: 100%;
        height: 3.15rem;
        overflow-y: scroll;
      }
      .tbodys::-webkit-scrollbar {
        display: none;
      }
      .tbodys {
        scrollbar-width: none;
        -ms-overflow-style: none;
        overflow-x: hidden;
        overflow-y: auto;
      }
      .tbody {
        width: 100%;
        min-height: .42rem;
        border: 1px solid #d0d6e3;
        border-radius: .03rem;
        font-size: .18rem;
        color: #161d2e;
        margin-top: .03rem;
        padding: 0 .3rem 0 .15rem;
      }
      .w500 {
        width: 5%;
        text-align: center;
      }
      .w7000 {
        width: 70%;
      }
      .w1000 {
        width: 10%;
        text-align: center;
      }
    }
    .btns {
      width: 100%;
      position: absolute;
      bottom: .34rem;
      .btn {
        width: 1.3rem;
        height: .4rem;
        margin-left: 1.12rem;
        line-height: .4rem;
        text-align: center;
        border-radius: .03rem;
        font-size: .22rem;
        cursor: pointer;
      }
      .btn.sure {
        background: linear-gradient(0deg, #00a366 0%, #00c37a 100%);
        color: #fff;
      }
      .btn.cancel {
        border: 1px solid #316eff;
        background: linear-gradient(0deg, #d9dde8 0%, #ffffff 100%);
        color: #505971;
      }
      .btn:first-child {
        margin-left: 0;
      }
    }
  }
}
</style>